package com.bicycle.rentalsystem.service.impl.admin;

import com.bicycle.rentalsystem.dao.admin.StationDao;
import com.bicycle.rentalsystem.dao.impl.admin.StationDaoImpl;
import com.bicycle.rentalsystem.pojo.admin.Page;
import com.bicycle.rentalsystem.pojo.admin.Station;
import com.bicycle.rentalsystem.service.admin.StationService;

import java.util.List;

/**
 * @author Third uncle
 * @date 2022/11/27 - 16:46
 */
public class StationServiceImpl implements StationService {
    StationDao stationDao=new StationDaoImpl();
    @Override
    public Page<Station> page(Integer pageNo, Integer pageSize) {
        Page<Station> page=new Page<>();
        //设置当前页码
        page.setPageNo(pageNo);
        //设置每页显示数量
        page.setPageSize(pageSize);
        //总记录数
        Integer total = stationDao.queryForPageTotalCount();
        //设置总记录数
        page.setPageTotalCount(total);
        //总页码数
        Integer pageTotal=total/pageSize;
        if(total%pageSize>0){
            pageTotal+=1;
        }
        //设置总页码数
        page.setPageTotal(pageTotal);
        //求当前开始索引的位置
        Integer begin=(page.getPageNo()-1)*pageSize;
        //求当前页数据
        List<Station> list = stationDao.queryForPageItems(begin, pageSize);
        //设置当前页数据
        page.setItems(list);

        return page;
    }

    @Override
    public void addStation(Station station) {
        stationDao.addStation(station);
    }

    @Override
    public void deleteStation(int aId) {
        stationDao.deleteStationById(aId);
    }

    @Override
    public List<Station> getStation() {
        List<Station> list = stationDao.getStation();
        return list;
    }
}
